package com.cq.hd.app.controller;

import com.cq.hd.app.biz.UserBiz;
import com.cq.hd.app.vo.WithdrawalPreVo;
import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.enums.biz.FinancialAccountTypeEnum;
import com.cq.hd.common.enums.biz.WithdrawalTypeEnum;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.TbWithdrawalBillApi;
import com.cq.hd.member.api.dto.WithdrawalApplyDto;
import com.cq.hd.member.api.dto.WithdrawalApplyPageDto;
import com.cq.hd.member.api.vo.WithdrawalApplyPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Collections;

@RestController
@RequestMapping("/withdrawal")
@Api(tags = "提现相关接口")
public class WithdrawalController {

    @Autowired
    private TbWithdrawalBillApi withdrawalBillApi;

    @Autowired
    private UserBiz userBiz;

    @ApiOperation(value = "预提现")
    @ApiResponse(response = WithdrawalPreVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/pre")
    public Result<WithdrawalPreVo> pre(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        return ResultGenerator.success(userBiz.preWithdrawal(appLoginUser));
    }

    @ApiOperation(value = "申请提现")
    @ApiImplicitParam(name = "withdrawalApplyDto", value = "实体", paramType = "body", dataType = "WithdrawalApplyDto")
    @PostMapping("/apply")
    public Result<Boolean> apply(@ApiIgnore @LoginUser AppLoginUser appLoginUser, @RequestBody WithdrawalApplyDto withdrawalApplyDto) {
        withdrawalApplyDto.setUserId(appLoginUser.getUserId());
        withdrawalApplyDto.setWithdrawalType(WithdrawalTypeEnum.AGENT_COMMISSION.getValue());
        withdrawalApplyDto.setFinancialAccountType(FinancialAccountTypeEnum.SELF.getValue());
        return withdrawalBillApi.apply(withdrawalApplyDto);
    }

    @ApiOperation(value = "提现记录")
    @ApiImplicitParam(name = "withdrawalApplyDto", value = "实体", paramType = "body", dataType = "WithdrawalApplyDto")
    @GetMapping("/page")
    public Result<Page<WithdrawalApplyPageVo>> page(@ApiIgnore @LoginUser AppLoginUser appLoginUser, WithdrawalApplyPageDto withdrawalApplyPageDto) {
        withdrawalApplyPageDto.setUserId(appLoginUser.getUserId());
        withdrawalApplyPageDto.setWithdrawalTypes(Collections.singletonList(WithdrawalTypeEnum.AGENT_COMMISSION.getValue()));
        return withdrawalBillApi.pageWithdrawalBill(withdrawalApplyPageDto);
    }

}
